#include "cpp-httplib/httplib.h"
#include <iostream>
#include <string>
#include "Searcher.hpp"

const std::string root_path = "./wwwroot";
const std::string out_path = "data/raw_html/output.txt";
int main()
{
    httplib::Server server;
    server.set_base_dir(root_path.c_str());
    ns_searcher::Searcher searcher;
    searcher.Init(out_path);
    searcher.InitStop();
    server.Get("/s",[&searcher](const httplib::Request& req,httplib::Response& res){
        if (!req.has_param("word")){
            res.set_content("搜索请输入关键字！","text/plain: charset=utf-8");
            return;
        }
        std::string word = req.get_param_value("word");
        std::cout << "用户输入关键字: " << word << std::endl;
        std::string json_string;
        searcher.Search(word,&json_string);
        res.set_content(json_string,"application/json");
    });

    server.listen("0.0.0.0",8081);
    return 0;
}
